<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<input type="text" id="input">
<body>
<script>
document.onkeypress = function (e){
    var code = e.keyCode;   // 键码
    console.log(code);
}
/*input.onkeypress = function (){
    console.log("按下了字符键盘");
}
input.onkeyup = function (){
    console.log("送开了键盘的按键");
}*/
</script>
</body>
</html>